package com.mcxx.modules.tool.service.impl;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class JinminUtils {

    public static String cutPhone(String phone,int number){
        if(StringUtils.isEmpty(phone)){
            return "";
        }
        String num = "0123456789";
        String returnPhone = "";
        for(int i = 0; i < phone.length(); i++){
            if(num.indexOf(phone.charAt(i)) >= 0){
                returnPhone += phone.charAt(i);
            }
        }
        if(returnPhone.length() > number){
            return returnPhone.substring(0,number);
        }else{
            return returnPhone;
        }
    }
    public static String getCityOrVill(String standType){
        if("01".equals(standType) || "03".equals(standType)){
            return "02";
        }else{
            return "01";
        }
    }

    public static String getNational(String nation) {
        if (StringUtils.isEmpty(nation)) {
            return "01";
        }
        if ("99".equals(nation)) {
            return "01";
        }
        String rnt = nation;
        if (rnt.length() <= 1) {
            rnt = "0" + nation;
            return rnt;
        }
        if (rnt.length() > 2) {
            rnt = "01";
            return rnt;
        }
        return nation;
    }

    public static String getWorkPower(String workPower) {
        if (StringUtils.isEmpty(workPower))
            return "1";
        if ("01".equals(workPower))
            return "1";
        if ("02".equals(workPower))
            return "2";
        if ("03".equals(workPower))
            return "3";
        if ("04".equals(workPower))
            return "4";
        return "1";
    }
    public static String getDisableLevel(String disType) {
        if (StringUtils.isEmpty(disType))
            return null;
        if ("01".equals(disType))
            return "1";
        if ("02".equals(disType))
            return "2";
        if ("03".equals(disType))
            return "3";
        if ("04".equals(disType))
            return "4";
        return "1";

    }
    public static String getEducation(String education) {
        if (StringUtils.isEmpty(education))
            return "99";
        if ("10".equals(education))
            return "14";
        if ("90".equals(education))
            return "00";
        return "99";
    }
    public static String getSickType(String serdisease) {
        if (StringUtils.isEmpty(serdisease))
            return null;
        if (serdisease.length() > 2)
            return "11";
        String[] sicks = new String[] {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
        List<String> list = Arrays.asList(sicks);
        if (!list.contains(serdisease))
            return "11";
        return serdisease;
    }

    public static String getSalvType(String busiType) {
        if ("110".equals(busiType)) {
            return "100";
        } else if ("130".equals(busiType)) {
            return "130";
        } else if ("500".equals(busiType)) {
            return "650";
        } else {
            return "99";
        }
    }


    public static Date getEndMonth(Date endMonth,String month) {
        int y = Integer.parseInt(month.substring(0, 4));
        int m = Integer.parseInt(month.substring(4, 6)) - 1;
        if(endMonth.getYear()+1900 == y && endMonth.getMonth() == m){
            m += 1;
            int year = endMonth.getYear()+1900;
            if (m >= 12) {
                year += 1;
                m = 0;
            }
            return new Date(year-1900, m, 1);
        }else{
            return endMonth;
        }
    }

    public static String createMemberId(String orderId,String memberId){
        String ret = orderId.substring(0,16)+memberId.substring(16);
        return ret;
    }

    public static void main(String[] args) {

        System.out.println(createMemberId("f2834b4eed824b2e8415af62f06c7ac0","8ac880465d3f4baa015d43e47a251059"));
    }
}
